package com.zking.ssm.controller;


import com.zking.ssm.model.HotelBrand;
import com.zking.ssm.model.HotelMember;
import com.zking.ssm.service.IHotelBrandService;
import com.zking.ssm.service.IHotelMemberService;
import com.zking.ssm.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController  //返回json格式的数据
@RequestMapping("/Member") //窄化路径

public class HotelMemberController {
    @Autowired
    private IHotelMemberService iHotelMemberService;
    @RequestMapping("/list")
    public Map<String,Object> list(HotelMember hotelMember){
        PageBean pageBean = new PageBean();
        List<HotelMember> list = iHotelMemberService.SelectAll(hotelMember, pageBean);
        Map<String,Object> map = new HashMap<>();
        if(list.size() >= 0){
            map.put("code",0);
            map.put("message","查询用户成功！");
            map.put("request",list);
        }else{
            map.put("code",-1);
            map.put("message","查询用户失败！");
        }
        return map;
    }

    @RequestMapping("/listStutas")
    public Map<String,Object> listStutas(HotelMember hotelMember){
        System.out.println(hotelMember);
        List<HotelMember> list = iHotelMemberService.SelectStutas(hotelMember);
        Map<String,Object> map = new HashMap<>();
        if(list.size() >= 0){
            map.put("code",0);
            map.put("message","查询用户成功！");
            map.put("request",list);
        }else{
            map.put("code",-1);
            map.put("message","查询用户失败！");
        }
        return map;
    }

    @RequestMapping("/add")
    public Map<String,Object> add(HotelMember hotelMember){
        System.out.println(hotelMember);
        int n = iHotelMemberService.insert(hotelMember);
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","增加用户成功！");
        }else{
            map.put("code",-1);
            map.put("message","增加用户失败！");
        }
        return map;
    }

    @RequestMapping("/del")
    public Map<String,Object> del(HotelMember hotelMember){
        int n = iHotelMemberService.deleteByPrimaryKey(hotelMember.getId());
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","删除用户成功！");
        }else{
            map.put("code",-1);
            map.put("message","删除用户失败！");
        }
        return map;
    }
    @RequestMapping("/update")
    public Map<String,Object> update(HotelMember hotelMember){
        System.out.println("前台传过来的参数"+hotelMember);

        int n = iHotelMemberService.updateByPrimaryKey(hotelMember);
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","修改用户成功！");
        }else{
            map.put("code",-1);
            map.put("message","修改用户失败！");
        }
        return map;
    }

    @RequestMapping("/get")
    public Map<String,Object> get(HotelMember hotelMember){
        HotelMember user = iHotelMemberService.selectByPrimaryKey(hotelMember.getId());
        Map<String,Object> map = new HashMap<>();
        if(user != null){
            map.put("code",0);
            map.put("message","查询用户成功！");
            map.put("request",user);
        }else{
            map.put("code",-1);
            map.put("message","查询用户失败！");
        }
        return map;
    }

}
